/**
 * RetrieveMetadata.java
 * Retrieves metadata associated with a media file for webpage display.
 */
package com.example.myproject;

import java.util.HashMap;
import java.util.Map;

public class RetrieveMetadata {
	
	public RetrieveMetadata(){}
	
	/**
	 * Returns a map containing metadata for a specified media file.
	 * @param fileId id of the media file.
	 * @param fileType File content type of the media file.
	 * @return Map containing metadata field names and contents for media file.
	 */
	public Map<String, String> retrieveInfo(String fileId, String fileType)
	{
		
		Long id = Long.parseLong(fileId);
		Map<String, String> info = new HashMap<String, String>();	
		if("audio".equals(fileType))
		{
			AudioUploadDAO audio = new AudioUploadDAO();
			AudioUploadDTO dto = audio.findById(id);
			info.put("title", dto.getTitle()==null?"":dto.getTitle());
			info.put("album", dto.getAlbum()==null?"":dto.getAlbum());
			info.put("genre", dto.getGenre()==null?"":dto.getGenre());
			info.put("caption", dto.getCaption()==null?"":dto.getCaption());
			info.put("series", "");
			info.put("episode", "");				
		}
		else if("video".equals(fileType))
		{
			VideoUploadDAO video = new VideoUploadDAO();
			VideoUploadDTO dto = video.findById(id);
			info.put("title", dto.getTitle()==null?"":dto.getTitle());
			info.put("series", dto.getSeries()==null?"":dto.getSeries());
			info.put("episode", dto.getEpisode()==null?"":dto.getEpisode());
			info.put("caption", dto.getCaption()==null?"":dto.getCaption());
			info.put("album", "");
			info.put("genre", "");			
		}
		else if("image".equals(fileType))
		{
			PictureUploadDAO picture = new PictureUploadDAO();
			PictureUploadDTO dto = picture.findById(id);
			info.put("title", dto.getTitle());	
			info.put("caption", dto.getCaption()==null?"":dto.getCaption());
			info.put("series", "");
			info.put("episode", "");
			info.put("album", "");
			info.put("genre", "");
		}
		else if("book".equals(fileType))
		{
			PictureUploadDAO picture = new PictureUploadDAO();
			PictureUploadDTO dto = picture.findById(id);
			info.put("title", dto.getTitle());	
			info.put("caption", dto.getCaption()==null?"":dto.getCaption());
			info.put("series", "");
			info.put("episode", "");
			info.put("album", "");
			info.put("genre", "");			
		}
			
		return info;
		
	}
	
}
